<?

class CustomColumnView extends DefaultView {
	function get_columns($viewname) {
                $meta = DbConn::get_meta_data($viewname);
                $columns = array();
                foreach($meta as $k=>$m){
			$m['column'] = $k;
			$m['realcolumn'] = $k;
			$columns[] = $m;
                }
		if (isset($meta['custom_columns'])) {
			$tablename = preg_replace('/_v$/', '', $viewname);
			$sql = 'select custom_column_name, column_index, id_custom_column_type, type_name from custom_columns join custom_column_types using (id_custom_column_type) where table_name = $1';
			$custom_columns = DbConn::query($sql, array($tablename));
			DbConn::log(print_r($custom_columns, TRUE));
			foreach ($custom_columns as $col) {
				$columns[] = array(column => $col[0], realcolumn => 'custom_columns['.$col[1].']', type => $col[3]);
				$this->sql['fields'] .= ', ' . 'custom_columns[' . $col[1] . '] as ' . $col[0];
			}
		}
		DbConn::log(print_r($columns, TRUE));
                return $columns;
	}
}

?>
